package org.wendu.wdoa.newassi.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wendu.wdoa.common.CurrentUser;
import org.wendu.wdoa.common.Result;
import org.wendu.wdoa.common.WdoaConstants;
import org.wendu.wdoa.common.token.TokenUtils;
import org.wendu.wdoa.newassi.dto.EmpDepDto;
import org.wendu.wdoa.newassi.dto.TaskAddDto;
import org.wendu.wdoa.newassi.dto.TaskNewassiQueryDto;
import org.wendu.wdoa.newassi.dto.TaskRecDto;
import org.wendu.wdoa.newassi.service.TaskNewassiService;

import java.util.Map;

@RestController
@RequestMapping("/newassi")
public class TaskNewassiApi {
    @Autowired
    private TaskNewassiService taskNewassiService;

    @GetMapping("/findTaskList")
    public Result findTaskList(@RequestHeader(WdoaConstants.HEADER_NAME_TOKEN) String clientToken, TaskNewassiQueryDto taskNewassiQueryDto){
        CurrentUser currentUser = TokenUtils.getCurrentUser(clientToken);
        Map<String,Object> page = taskNewassiService.findLeaderTaskList(currentUser.getUserId(),taskNewassiQueryDto);
        return Result.OK(page);
    }
    @PostMapping("/addNewTask")
    public Result addNewTask(@RequestHeader(WdoaConstants.HEADER_NAME_TOKEN) String clientToken,@RequestBody TaskAddDto taskAddDto){
        CurrentUser currentUser = TokenUtils.getCurrentUser(clientToken);
        taskNewassiService.addNewTask(currentUser.getUserId(),taskAddDto);
        return Result.OK();
    }
    @GetMapping("/findDepEmpList")
    public Result findDepEmpList(@RequestHeader(WdoaConstants.HEADER_NAME_TOKEN) String clientToken, EmpDepDto empDepDto){
        CurrentUser currentUser = TokenUtils.getCurrentUser(clientToken);
        Map<String,Object> page = taskNewassiService.findDepEmpList(currentUser.getUserId(),empDepDto);
        return Result.OK(page);
    }

    @PostMapping("/addEmpDepTask/{task_id}")
    public Result addEmpDepTaskMulti(@RequestBody String[] eids,  TaskRecDto taskRecDto,@PathVariable String task_id){
        taskNewassiService.addEmpDepTaskMultiById(eids,taskRecDto,task_id);
        return Result.OK();
    }
    @PostMapping("/updateTask")
    public Result updateTask(@RequestBody TaskNewassiQueryDto taskNewassiQueryDto){
        taskNewassiService.updateTask(taskNewassiQueryDto);
        return Result.OK();
    }
    @PostMapping("/queDingTask")
    public Result queDingTask(@RequestBody TaskNewassiQueryDto taskNewassiQueryDto){
        taskNewassiService.queDingTask(taskNewassiQueryDto);
        return Result.OK();
    }

}
